/**
 * 小程序更新检测
 */
 import Taro from "@tarojs/taro"
 import key from "./storageKeyMap"
 import { Storage, showToast, showModal } from './tools/public'
 
  function updateMiniProgram() {
   const updateManager = Taro.getUpdateManager()
 
    updateManager.onCheckForUpdate(res => {
      console.log(res);
   })
 
   updateManager.onUpdateReady(() => {
     showModal('更新提示', '新版本已经准备好，立即更新使用', {
       showCancel: false,
       confirmText: '好'
     }).then(res => {
       if (!res.confirm) return
       updateManager.applyUpdate()
       Storage.removeSync(key.LOGIN_TOKEN_KEY)
     }, () => {})
   })
 
    updateManager.onUpdateFailed(() => {
     showToast('新版本下载失败')
   })
 }
 
 export default updateMiniProgram
 